<!--
 * @Author: fengxx
 * @Date: 2025-09-10 17:57:15
 * @LastEditors: fengxx
 * @LastEditTime: 2025-10-24 10:57:54
-->
<script setup lang="ts">
import { Expand, Fold, ChromeFilled } from '@element-plus/icons-vue'
import { computed, ref } from 'vue'
import menuRoutes from '@/router/menuRoutes'
const isCollapse = ref(false)

const breadPath = ref([
  {
    name: '首页',
    path: '/home',
  },
])

// 左菜单的展开收起
const changeMenuCollapse = () => {
  isCollapse.value = !isCollapse.value
}

const asideClass = computed(() => (isCollapse.value ? 'collapse-cls' : 'expand-cls'))
</script>
<template>
  <div class="common-layout">
    <el-container class="container-style">
      <el-aside width="200px" class="aside-style" :class="asideClass">
        <h1 class="menu-title">
          <el-icon class="title-icon">
            <ChromeFilled />
          </el-icon>
          <span class="title-txt">智能学生考勤系统</span>
        </h1>
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          :router="true"
          background-color="rgb(48, 65, 86)"
          text-color="rgb(191, 203, 217)"
          active-text-color="rgb(64, 158, 255)"
          :collapse="isCollapse"
        >
          <!-- 动态生成菜单项 -->
          <template v-for="value in menuRoutes" :key="value.path">
            <my-menu-item
              v-if="value.path !== '/'"
              :key="value.path"
              :menu-item="value"
            ></my-menu-item>
            <template v-else>
              <my-menu-item
                v-for="value1 in value.children"
                :key="value1.path"
                :menu-item="value1"
                :path="`/${value1.path}`"
              ></my-menu-item>
            </template>
          </template>

          <!-- 静态配置菜单项 -->
          <!-- <el-sub-menu index="/user" class="sub-menu-style">
            <template #title>
              <el-icon><icon-menu /></el-icon>
              <span>用户模块</span>
            </template>
<el-menu-item index="/user/list" route="/user/list">
  <el-icon><icon-menu /></el-icon>
  <span>用户列表</span>
</el-menu-item>
</el-sub-menu>
<el-menu-item index="/" route="/">
  <el-icon><icon-menu /></el-icon>
  <span>主页面</span>
</el-menu-item>
<el-menu-item index="/about" route="/about">
  <el-icon>
    <document />
  </el-icon>
  <span>关于</span>
</el-menu-item>
<el-menu-item index="/userList" route="/userList">
  <el-icon>
    <setting />
  </el-icon>
  <span>用户列表</span>
</el-menu-item>
<el-menu-item index="/test" route="/test">
  <el-icon>
    <setting />
  </el-icon>
  <span>测试列表</span>
</el-menu-item>
<el-menu-item index="/productList" route="/productList">
  <el-icon>
    <setting />
  </el-icon>
  <span>商品列表</span>
</el-menu-item>
<el-menu-item index="/todo" route="/todo">
  <el-icon>
    <setting />
  </el-icon>
  <span>待办事件</span>
</el-menu-item> -->
        </el-menu>
      </el-aside>
      <el-container class="main-style">
        <el-header class="header-style">
          <el-icon @click="changeMenuCollapse" class="header-icon">
            <Expand v-if="isCollapse" />
            <Fold v-else />
          </el-icon>
          <span>{{ $route.meta.title }}</span>
          <!-- <el-breadcrumb separator="/">
            <el-breadcrumb-item
              v-for="value in breadPath"
              :key="value.path"
              :to="value.path"
              :style="{ color: $route.path === value.path ? '#97a8be' : '#303133' }"
            >
              {{ value.name }}
            </el-breadcrumb-item>
          </el-breadcrumb> -->
        </el-header>
        <el-main>
          <!-- <RouterView /> -->
          <!-- <router-view v-slot="{ Component }">
            <component :is="Component" />
          </router-view> -->
          <!-- <router-view v-slot="{ Component }">
            <transition>
            <keep-alive exclude="HomeView">
              <component :is="Component" />
            </keep-alive>
            </transition>
          </router-view> -->
          <RouterView v-slot="{ Component }">
            <template v-if="Component">
              <!-- <Transition mode="out-in"> -->
              <!-- <KeepAlive> -->
              <!-- <Suspense> -->
              <!-- 主要内容 -->
              <component :is="Component"></component>

              <!-- 加载中状态 -->
              <!-- <template #fallback> 正在加载... </template> -->
              <!-- </Suspense> -->
              <!-- </KeepAlive> -->
              <!-- </Transition> -->
            </template>
          </RouterView>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<style scoped>
/* .v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}
.v-enter-from,
.v-leave-to {
  opacity: 0;
} */

.common-layout {
  height: 100%;
  overflow: hidden;
}

.container-style {
  height: 100%;
  overflow: hidden;
}

.aside-style {
  background-color: rgb(48, 65, 86);
  transition: width 0.3s;
  height: 100%;
}

.collapse-cls {
  width: 64px;

  .title-icon {
    margin: 0;
  }

  .title-txt {
    display: none;
  }
}

.expand-cls {
  width: 200px;

  .title-icon {
    margin-right: 8px;
  }

  .title-txt {
    display: inline-block;
    width: 160px;
    white-space: nowrap;
  }
}

.menu-title {
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 45px;
}

.el-menu-vertical-demo {
  border-right: none;
}

.main-style {
  height: 100%;
}

.header-style {
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  display: flex;
  align-items: center;
  .header-icon {
    margin-right: 10px;
    font-size: 22px;
    cursor: pointer;
  }
}
</style>
